package br.ufu.si.bo;

import java.util.List;

import br.ufu.si.dao.GenericDAO;

@SuppressWarnings({"rawtypes", "unchecked"})
public class GenericBO {
	
	GenericDAO dao;
	
	public GenericBO() {
		dao = new GenericDAO();
	}
	
	public List findByExample(Object ex){
		try{
			return dao.findByExample(ex);
		} finally {
			dao.close();
		}
	}
	
	public List findAll(Class clazz){
		try {
			return dao.findAll(clazz);
		} finally {
			dao.close();
		}
	}
	
	public void saveOrUpdate(Object objeto){

		try{
			
			dao.beginTransaction();
			dao.saveOrUpdate(objeto);
			dao.commit();
			
		} catch (Exception e) {
			
			dao.rollback();
			e.printStackTrace();
			
		} finally {
			
			dao.close();
			
		}
		
	}
	
	public void save(Object objeto){

		try{
			
			dao.beginTransaction();
			dao.save(objeto);
			dao.commit();
			
		} catch (Exception e) {
			
			dao.rollback();
			e.printStackTrace();
			
		} finally {
			
			dao.close();
			
		}
		
	}
	
}
